package com.hex.ds.hdtp.core.app.data.contrast.converter;

import com.hex.ds.hdtp.core.app.common.entity.BasicContrastInfo;
import com.hex.ds.hdtp.core.app.common.entity.BasicTransferInfo;
import com.hex.ds.hdtp.core.app.data.contrast.dto.CrossDbContrastCommonDto;
import com.hex.ds.hdtp.core.app.data.contrast.dto.CrossDbContrastDto;
import com.hex.ds.hdtp.core.app.data.contrast.dto.response.CrossDbContrastListResponseDto;
import com.hex.ds.hdtp.core.app.data.contrast.dto.response.CrossDbContrastTemplateResponseDto;
import com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastTaskPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * @Package: com.hex.ds.hdtp.core.app.data.contrast.converter
 * @ClassName ICrossDbContrastConverter
 * @Description: 跨库比对参数转换
 * @Author: wz.li
 * @Date 2023/7/26 14:58
 * @Version v2.0.2
 **/
@Mapper(componentModel = "spring")
public interface ICrossDbContrastConverter {

    @Mapping(target = "contrastCommon.contrastTaskPkId", source = "contrastTask.pkId")
    @Mapping(target = "contrastCommon.contrastListPkId", source = "contrastList.pkId")
    @Mapping(target = "contrastCommon.contrastScene", source = "contrastList.contrastScene")
    @Mapping(target = "contrastCommon.serverPkId", source = "contrastTask.serverPkId")
    @Mapping(target = "contrastCommon.sourceCode", source = "contrastList.sourceCode")
    @Mapping(target = "contrastCommon.sourceSchema", source = "contrastList.sourceDbName")
    @Mapping(target = "contrastCommon.sourceTable", source = "contrastList.sourceTableName")
    @Mapping(target = "contrastCommon.contrastSchema", source = "contrastList.contrastDbName")
    @Mapping(target = "contrastCommon.contrastTable", source = "contrastList.contrastTableName")
    @Mapping(target = "contrastCommon.contrastCode", source = "contrastList.contrastCode")
    @Mapping(target = "contrastCommon.tableTransferPkId", source = "contrastList.tableTransferPkId")
    @Mapping(target = "contrastTableStructure.tableStructureMappingPkId", source = "contrastList.tableStructureMappingPkId")
    @Mapping(target = "contrastTableStructure.isCreateTable", source = "contrastTemplate.isCreateTable")
    @Mapping(target = "contrastTableStructure.isContrastPartitionField", source = "contrastTemplate.isContrastPartitionField")
    @Mapping(target = "contrastTableStructure.isContrastFieldCount", source = "contrastTemplate.isContrastFieldCount")
    @Mapping(target = "contrastTableStructure.isContrastFieldName", source = "contrastTemplate.isContrastFieldName")
    @Mapping(target = "contrastTableStructure.isContrastFieldType", source = "contrastTemplate.isContrastFieldType")
    @Mapping(target = "contrastTableStructure.isContrastFieldLength", source = "contrastTemplate.isContrastFieldLength")
    @Mapping(target = "contrastTableStructure.isContrastFieldPrecision", source = "contrastTemplate.isContrastFieldPrecision")
    @Mapping(target = "contrastTableStructure.isContrastEncoded", source = "contrastTemplate.isContrastEncoded")
    @Mapping(target = "contrastDataSummary.isHasData", source = "contrastTemplate.isHasData")
    @Mapping(target = "contrastDataSummary.isStatisticsDataCount", source = "contrastTemplate.isStatisticsDataCount")
    @Mapping(target = "contrastDataSummary.isSumCharLength", source = "contrastTemplate.isSumCharLength")
    @Mapping(target = "contrastDataSummary.isSumCharTrimLength", source = "contrastTemplate.isSumCharTrimLength")
    @Mapping(target = "contrastDataSummary.isStatisticsNumberSum", source = "contrastTemplate.isStatisticsNumberSum")
    @Mapping(target = "contrastDataSummary.isMaxCharLength", source = "contrastTemplate.isMaxCharLength")
    @Mapping(target = "contrastDataSummary.removeRepeatCountField", source = "contrastList.removeRepeatCountField")
    @Mapping(target = "contrastDataSummary.groupCountField", source = "contrastList.groupCountField")
    @Mapping(target = "contrastDataSummary.countField", source = "contrastList.countField")
    @Mapping(target = "contrastDataSummary.sumField", source = "contrastList.sumField")
    @Mapping(target = "contrastDataSummary.trimField", source = "contrastList.trimField")
    @Mapping(target = "contrastDataSummary.emptyField", source = "contrastList.emptyField")
    @Mapping(target = "contrastDataSummary.customSql", source = "contrastList.customSql")
    @Mapping(target = "contrastDataSummary.whereCondition", source = "contrastList.whereCondition")
    @Mapping(target = "contrastDataSummary.excludeFields", source = "contrastList.excludeField")
    @Mapping(target = "contrastSampleData.isAllField", source = "contrastTemplate.isAllField")
    @Mapping(target = "contrastSampleData.isCharNullToEmpty", source = "contrastTemplate.isCharNullToEmpty")
    @Mapping(target = "contrastSampleData.isNumberNullToZero", source = "contrastTemplate.isNumberNullToZero")
    @Mapping(target = "contrastSampleData.isSampleData", source = "contrastTemplate.isMaxFaultTolerance")
    @Mapping(target = "contrastSampleData.sampleDataCount", source = "contrastTemplate.maxFaultToleranceNum")
    @Mapping(target = "contrastSampleData.excludeField", source = "contrastList.excludeField")
    @Mapping(target = "contrastSampleData.trimField", source = "contrastList.trimField")
    @Mapping(target = "contrastSampleData.dataExtractScope", source = "contrastTemplate.dataExtractScope")
    @Mapping(target = "contrastSampleData.lessExtractScopeType", source = "contrastTemplate.lessExtractScopeType")
    @Mapping(target = "contrastSampleData.lessExtractScopeCustom", source = "contrastTemplate.lessExtractScopeCustom")
    @Mapping(target = "contrastSampleData.greaterExtractScopeType", source = "contrastTemplate.greaterExtractScopeType")
    @Mapping(target = "contrastSampleData.greaterExtractScopeCustom", source = "contrastTemplate.greaterExtractScopeCustom")
    @Mapping(target = "contrastSampleData.whereCondition", source = "contrastList.whereCondition")
    @Mapping(target = "contrastSampleData.sortField", source = "contrastList.sortField")
    CrossDbContrastDto toCrossDbContrastDto(CrossDbContrastTaskPo contrastTask,
                                            CrossDbContrastTemplateResponseDto contrastTemplate,
                                            CrossDbContrastListResponseDto contrastList);

    /**
     * @Method toBasicContrastInfo
     * @Param
     * @param contrastCommon
     * @Return com.hex.ds.hdtp.core.app.common.entity.BasicContrastInfo
     * @Description 跨库对比-公共参数DTO对象转为基础对比信息对象
     * @Author Wang zhihao
     * @Date 2023/8/18 10:38
     * @Version V1.0
     */
    BasicContrastInfo toBasicContrastInfo(CrossDbContrastCommonDto contrastCommon);


    /**
     * @Method toBasicTransferInfo
     * @Param contrastCommon
     * @Return com.hex.ds.hdtp.core.app.common.entity.BasicTransferInfo
     * @Description 脱离表迁移获取字段映射时参数对象转为迁移基础实体类
     * @Author gj.xu
     * @Date 2024/3/4 17:53
     * @Version V2.0
     */
    @Mapping(target = "sourceCode", source = "sourceCode")
    @Mapping(target = "sourceSchema", source = "sourceSchema")
    @Mapping(target = "sourceTable", source = "sourceTable")
    @Mapping(target = "targetCode", source = "contrastCode")
    @Mapping(target = "targetSchema", source = "contrastSchema")
    @Mapping(target = "targetTable", source = "contrastTable")
    BasicTransferInfo toBasicTransferInfo(BasicContrastInfo contrastCommon);
}
